package cn.zcib.film.controller;

import cn.zcib.film.anno.Record;
import cn.zcib.film.bean.Play;
import cn.zcib.film.bean.vo.PlayVO;
import cn.zcib.film.service.PlayService;
import cn.zcib.film.util.DataGridViewResult;
import cn.zcib.film.util.SystemConstants;
import com.alibaba.fastjson.JSON;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;

@RestController
@RequestMapping("/play")
public class PlayController {
    @Autowired
    private PlayService playService;
    /**
     * 上映电影列表
     * @return
     */
    @RequestMapping("/list")
    public DataGridViewResult findPlayList(PlayVO playVO){
        //设置分页信息
        PageHelper.startPage(playVO.getPage(),playVO.getLimit());
        //调用查询上映电影列表方法
        List<Play> plays = playService.findPlayList(playVO);
        //创建分页对象
        PageInfo<Play> pageInfo = new PageInfo<>(plays);

//        System.out.println("pageInfo = " + pageInfo);
        return new DataGridViewResult(pageInfo.getTotal(),pageInfo.getList());
    }

    /**
     * 撤档
     * @return
     */
    @RequestMapping("/cancel")
    public String  cancelPlay(Integer playId){
        HashMap<String, Object> map = new HashMap<>();

        if (playService.cancelPlay(playId)>0){
            map.put(SystemConstants.SUCCESS, true);
            map.put(SystemConstants.MESSAGE, "已撤档");
        }else {
            map.put(SystemConstants.SUCCESS, false);
            map.put(SystemConstants.MESSAGE, "撤档失败");
        }
        return JSON.toJSONString(map);
    }


}
